/****************************************************************************
 *   This file is part of Q2D.                                              *
 *                                                                          *
 *   Q2D is free software: you can redistribute it and/or modify            *
 *   it under the terms of the GNU General Public License as published by   *
 *   the Free Software Foundation, either version 3 of the License, or      *
 *   (at your option) any later version.                                    *
 *                                                                          *
 *   Q2D is distributed in the hope that it will be useful,                 *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *   GNU General Public License for more details.                           *
 *                                                                          *
 *   You should have received a copy of the GNU General Public License      *
 *   along with Q2D.  If not, see <http://www.gnu.org/licenses/>.           *
 *                                                                          *
 ****************************************************************************/

/*
 * SUBCLASSING
 *
 * bool notifyMerchant(merchantAction action, QVariant item, int number);
 * notify merchant & perform update on the merchant source as needed
 */

#ifndef MERCHANT_H
#define MERCHANT_H

#include <QtCore/QObject>
#include "weapon/weapon.h"
#include <QtCore/QPair>
#include <QtCore/QList>
#include <QtCore/QVariant>

class Merchant : public QObject {
        Q_OBJECT
        Q_DISABLE_COPY(Merchant)
        Q_PROPERTY(QString name READ getName WRITE setName)
        Q_PROPERTY(bool buyingAuthorised READ isBuyingAuthorised WRITE setBuyingAuthorised);
        Q_PROPERTY(bool sellingAuthorised READ isSellingAuthorised WRITE setSellingAuthorised);
public:
    Merchant();
        
    void setName(QString name);
    QString getName();

    bool isBuyingAuthorised();
    void setBuyingAuthorised(bool auth);

    bool isSellingAuthorised();
    void setSellingAuthorised(bool auth);

    bool weaponsAvailable();
    //bool armorsAvailable();
    //bool goodsAvailable();

    uint moneyRemaining();

    bool add(Weapon weapon, int number, qreal price = -1);
    bool remove(Weapon weapon, int number);
    bool buy(Weapon weapon, int number, qreal price = -1);
    bool sell(Weapon weapon, int number, qreal price = -1);
    bool changePrice(Weapon weapon, qreal price);
    int numberAvailable(Weapon weapon);

    //void add(Armor armor, int number);
    //bool remove(Armor armor, int number);
    //bool buy(Armor armor, int number);
    //bool sell(Armor armor, int number);
    //int numberAvailable(Armor armor);

    //void add(Good good, int number);
    //bool remove(Good good, int number);
    //bool buy(Good good, int number);
    //bool sell(Good good, int number);
    //int numberAvailable(Good good);

private:
    QString name;
    bool buyingAuthorised;
    bool sellingAuthorised;

    enum merchantAction{ WEAPON_ADDED, WEAPON_REMOVED, WEAPON_BOUGHT, WEAPON_SOLD, WEAPON_PRICE,
                         ARMOR_ADDED, ARMOR_REMOVED, ARMOR_BOUGHT, ARMOR_SOLD, ARMOR_PRICE,
                         GOOD_ADDED, GOOD_REMOVED, GOOD_BOUGHT, GOOD_SOLD, GOOD_PRICE
    };

    uint money;

    QList< QPair<Weapon, QPair<int, qreal> > > weaponList;
    //QList< QPair<Armor, int> > armorList;
    //QList< QPair<Good, int> > goodList;

    bool notifyMerchant(merchantAction action, QVariant * item = NULL, int number = -1, qreal price = -1);
    bool update();

    int weaponIndex(Weapon &weapon);

signals:
    void updated();
    void itemBought();
    void itemSold();
    void itemAdded();
    void itemRemoved();

};

#endif // MERCHANT_H
